package Classes.GameUtils
{
	import UIComponents.FlatInfo;
	
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	import flash.system.Security;
	import flash.system.SecurityDomain;

	public class LoadImg
	{
		private static var _instance:LoadImg; /*静态引用*/
		private var imgLoader:Loader;
		public function LoadImg()
		{
			imgLoader=new Loader();
		}
		
		
		/*getter & setter*/
		public static function get instance():LoadImg
		{
			if (!_instance)
				_instance=new LoadImg;
			return _instance;
		}
		
//		private var bm:Bitmap;
		private var callBack:Function;
		public function loadingImg(imgUrl:String,call:Function):void
		{
			Security.allowDomain("*");
			if(imgUrl=="") return;
			this.callBack=call;
			var urlReq:URLRequest=new URLRequest(imgUrl);
//			var context:LoaderContext;
//			if(FlatInfo.isOnLocalHost==1)
//			{
				imgLoader.load(urlReq);
//				trace("在本机");
//			}else{
//				var context:LoaderContext= new LoaderContext(true, ApplicationDomain.currentDomain,SecurityDomain.currentDomain);
//				imgLoader.load(urlReq,context);
//			}
//			imgLoader.load(urlReq);
			
			imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHanlder);
			function completeHanlder(evt:Event):void
			{
				imgLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,completeHanlder);
//				bm=Bitmap(imgLoader.content);
				callBack(imgLoader);
			}
		}
	}
}